/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.definition;


import java.util.Collection;
import java.util.List;

import dex.compiler.model.statement.Block;
import dex.compiler.model.type.TypeNode;
import dex.misc.Conversion;
import dex.misc.Converter;


/**
 * A callable definition.  Common superclass for functions, methods and constructors.
 */
public abstract class Callable extends Member {


	/**
	 * The name/type pairs that describe the callable's parameters.
	 */
	private List<TypedName> parameters;


	/**
	 * The body of the callable.
	 */
	private Block body;
	
	
	/**
	 * Constructs a new callable definition.
	 * 
	 * @param dp  contains the name, place, modifier, attributes and comment of the new callable
	 * @param parameters  the parameters of the new callable
	 * @param body   the body of the new callable
	 */
	public Callable(DefinitionParams dp, List<TypedName> parameters, Block body) {
		super(dp);
		if (parameters == null) {
			throw new IllegalArgumentException("parameters may not be null");
		}
		if (body == null) {
			throw new IllegalArgumentException("body may not be null");
		}
		this.parameters = parameters;
		this.body = body;
	}


	/**
	 * Returns the body of the callable.
	 * 
	 * @return  the body of the callable
	 */
	public Block getBody() {
		return body;
	}


	/**
	 * Returns the parameter definitions for the callable.
	 * 
	 * @return   the parameters
	 */
	public List<TypedName> getParameters() {
		return parameters;
	}
	

	/**
	 * Returns the parameter type nodes for the callable.
	 * The returned collection will iterate over the type nodes
	 * in the order the parameters were declared.
	 * 
	 * @return  an unmodifiable collection of this callable's type nodes
	 */
	public Collection<TypeNode> getParameterTypes() {
		return new Conversion<TypedName,TypeNode>(parameters, new Converter<TypedName,TypeNode>() {
			public TypeNode convert(TypedName tn) {
				return tn.getType();
			}
		});
	}


	public abstract boolean isVoid();

}
